﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;

public class Element : MonoBehaviour
{
    public bool mine;
    // Use this for initialization
    void Start()
    {
        mine = Random.value < 0.15f;

        EventTrigger trigger = gameObject.AddComponent<EventTrigger>();
        EventTrigger.Entry entry = new EventTrigger.Entry();
        entry.eventID = EventTriggerType.PointerClick;
        entry.callback.AddListener(OnClickCell);
        trigger.triggers.Add(entry);
    }

    // Update is called once per frame
    void Update()
    {
        
    }
    private void OnClickCell(BaseEventData eventData)
    {
        //print("点击了？"+mine);
        if (mine)
        {
            Main._instance.UncoverMines();
            //print("游戏失败");
        }else
        {
            Main._instance.GetPosition(GetComponent<Image>());
            //添加游戏胜利
        }
    }

    void LoadTexture(int index)
    {
        if (mine)
        {
            GetComponent<Image>().sprite = Main._instance.mine;
        }
        else
        {
            GetComponent<Image>().sprite = Main._instance.cellList[index];
        }
    }
}
